import 'package:shelf/shelf_io.dart' as shelf_io;
import 'package:shelf_proxy/shelf_proxy.dart';
//源地址  https://juejin.im/post/6844904080179986440
import 'package:http/http.dart' as http;
//前端页面访问本地域名
const String LocalHost = '127.0.0.1';

//前端页面访问本地端口号
const int LocalPort = 4040;

//目标域名，这里我们将要请求火狐的这个地址
const String TargetUrl ='https://wanandroid.com';
 //'https://developer.mozilla.org';
Future main() async {


  var client =http.Client();
  var server = await shelf_io.serve(
  proxyHandler(TargetUrl,  client: client),
  LocalHost,
  LocalPort,
  );

  // 添加上跨域的这几个header
  server.defaultResponseHeaders.add('Access-Control-Allow-Origin', '*');
  server.defaultResponseHeaders.add('Access-Control-Allow-Credentials', true);
  print('Serving at http://${server.address.host}:${server.port}');
}
 